/**
 * 
 */
package com.curluin.model;

import com.curluin.approximateShapes.ApproximateShape;
import com.curluin.approximateShapes.Rectangle;
import com.curluin.math.MyVector;
import com.curluin.scene.Cube;
import com.curluin.scene.Node;
import com.curluin.scene.TextureNode;
import com.curluin.scene.TriangleMesh;

/**
 * @author alex
 *
 */
public class Ground extends ModelObject {

	/**
	 * GamePhase in which this ground-object is settled
	 */
	private int gamePhase;

	/**
	 * Friction of this Ground
	 */
	private float friction;
	/**
	 * b: width, h: height, l: length of Ground
	 */
	private float  b, h, l;

	private float[] textureSizePerDim;

	private int[] numTexturePerDim;

	/**
	 * Constructor
	 */
	public Ground(float friction,int gamePhase,MyVector position, int positionMode,float b, float h, float l, MyVector color, int consitency) {
		super(position,consitency);
		this.b=b; this.h=h; this.l=l;
		this.gamePhase=gamePhase;
		this.friction=friction;
		node.setColor(color);
		debugColor=color;
		if(this.getClass().equals(Ground.class)){
			initialize(position, positionMode);
		}
	}
	
	public Ground(float friction,int gamePhase,MyVector position, int positionMode,float b, float h, float l, final int textureResourceId, int consitency) {
		this(friction, gamePhase, position, positionMode, b, h, l, TriangleMesh.GREEN, consitency);
		
		TextureNode texNode = new TextureNode(textureResourceId);
	    texNode.addChild(this.node.getChildren().firstElement());
		this.node.getChildren().clear();
		this.node.addChild(texNode);
	}

	public Ground(float friction,int gamePhase,MyVector position, int positionMode, float[] textureSize, int[] numTexturePerDim, final int textureResourceId, int consitency) {
		super(position,consitency);
		this.numTexturePerDim = numTexturePerDim;
		this.textureSizePerDim = textureSize;
		this.gamePhase=gamePhase;
		this.friction=friction;
		node.setColor(TriangleMesh.GREEN);
		debugColor=TriangleMesh.GREEN;
		if(this.getClass().equals(Ground.class)){
//			Log.e(LOG_TAG, "LOOK HERE" );
			initialize(position, positionMode);
//			Log.e(LOG_TAG, "pos "+node.getCenter()+" size "+getSize());
			TextureNode texNode = new TextureNode(textureResourceId);
		    texNode.addChild(this.node.getChildren().firstElement());
			this.node.getChildren().clear();
			this.node.addChild(texNode);
		}
	}
	

	@Override
	protected Node composeGraphics() {
		if(textureSizePerDim!=null && numTexturePerDim !=null) return new Cube(MyVector.makeVector3(0, 0, 0), textureSizePerDim, numTexturePerDim, node.color);
		return new Cube(MyVector.makeVector3(0, 0, 0), b, h, l, node.color);
	}

	@Override
	protected ApproximateShape initializeApproximateShape() {
		Rectangle r = new Rectangle(node);
		return r;
	}

	public int getGamePhase(){
		return gamePhase;
	}

	/**
	 * Friction of this ground
	 * @return
	 */
	public float getFriction() {
		return friction;
	}	

}
